package com.shujia;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

public class Demo1Producer {
    public static void main(String[] args) {
        //1、创建生产者
        Properties properties = new Properties();
        properties.setProperty("bootstrap.servers", "master:9092,node1:9092,node2:9092");

        properties.setProperty("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        properties.setProperty("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        KafkaProducer<String, String> producer = new KafkaProducer<>(properties);

        //2、生产数据
        ProducerRecord<String, String> record = new ProducerRecord<>("words", "java");
        producer.send(record);
        producer.flush();

        //关闭生产者
        producer.close();
    }
}
